﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using System.IO;


/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod(EnableSession = true)]
    public bool delPic(string fileName)
    {
        string sql = string.Format("select LuJing from TuPianKu where ChongMingMing='{0}'", fileName);
        string LuJing = string.Empty;
        object obj = DbHelper.ExecuteScalar(CommandType.Text, sql, null);
        if (obj != null)
        {
            LuJing = obj.ToString();
        }
        if (LuJing != string.Empty)
        {
            string path = Path.Combine(LuJing.Replace("../", ""), fileName);
            if (File.Exists(Server.MapPath(path)))
            {
                File.Delete(Server.MapPath(path));
                string thumb = Path.Combine(LuJing.Replace("../", ""), "thumb_" + fileName);
                if (File.Exists(Server.MapPath(thumb)))
                {
                    File.Delete(Server.MapPath(thumb));
                }
            }
            sql = string.Format("delete from TuPianKu where ChongMingMing='{0}'", fileName);
            int num = DbHelper.ExecuteNonQuery(CommandType.Text, sql, null);
            return true;
        }
        else
        {
            return false;
        }
    }

}

